#include "stm32f10x.h"


void trans_m2m_dma(uint32_t source_addr,uint32_t dest_addr){

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
    
    DMA_InitTypeDef dma_def;

    
    //dma_def.DMA_BufferSize=sizeof(uint32_t);
    
    // 外围电路是否是此次DMA的起点或终点
    dma_def.DMA_DIR=DMA_DIR_PeripheralDST;
    dma_def.DMA_M2M=DMA_M2M_Enable;
    dma_def.DMA_MemoryBaseAddr=source_addr;
    dma_def.DMA_MemoryDataSize=DMA_MemoryDataSize_Word;
    // 内存地址增加
    dma_def.DMA_MemoryInc=DMA_MemoryInc_Enable;
    
    // m2m模式下此配置无效
    //dma_def.DMA_Mode=;
    dma_def.DMA_PeripheralBaseAddr=dest_addr;
    dma_def.DMA_PeripheralDataSize= DMA_PeripheralDataSize_Word;
    dma_def.DMA_PeripheralInc=DMA_PeripheralInc_Enable;
    dma_def.DMA_Priority=DMA_Priority_Low;
    
    DMA_Init(DMA1_Channel5,&dma_def);


    DMA_ITConfig(DMA1_Channel5,DMA_IT_TC,ENABLE);
    
    NVIC_InitTypeDef nvic;
    
    nvic.NVIC_IRQChannel = DMA1_Channel5_IRQn;
    
    nvic.NVIC_IRQChannelCmd = ENABLE;
    nvic.NVIC_IRQChannelPreemptionPriority=2;
    nvic.NVIC_IRQChannelSubPriority=2;
    
    
    
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    NVIC_Init(&nvic);
    
    
}

